#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "std_msgs/msg/int32.hpp"

class TopicPublish01:public rclcpp::Node
{
    public:
        TopicPublish01(std::string name):Node(name){
            RCLCPP_INFO(this->get_logger(),"%s_kaiji",name.c_str());
            // 创建发布者，提供主题名称和QoS策略
            command_publisher_ = this->create_publisher<std_msgs::msg::Int32>("command_topic",10);
            //chuangjianshijian
            timer_=this->create_wall_timer(std::chrono::milliseconds(500),std::bind(&TopicPublish01::timer_callback,this));
        }
    private:
        void timer_callback(){
            std_msgs::msg::Int32 number;
            number.data=100;
            RCLCPP_INFO(this->get_logger(),"playing:%d",number.data);
            command_publisher_->publish(number);
        }
        // 声名定时器指针
        rclcpp::TimerBase::SharedPtr timer_;
        // 声明话题发布者指针
        rclcpp::Publisher<std_msgs::msg::Int32>::SharedPtr command_publisher_;
};

int main(int argc, char **argv){
    rclcpp::init(argc,argv);
    /*创建对应节点的共享指针对象*/
    auto node=std::make_shared<TopicPublish01>("topic_publish_01");
    /* 运行节点，并检测退出信号*/
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}